import { PetNewBaseView } from "./PetNewBaseView";
import { Language } from "../../../../extend/language/Language";
import { SPetInfo } from "../../../../Message/Game/SPetInfo";
import { PetUtil } from "./info/PetUtil";
import { PetReincarnateConfig } from "../../resource/PetReincarnateConfig";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { MsgManager } from "../../manager/MsgManager";
import { Alert } from "../../../../com/mui/controls/Alert";
import { PetRebornVo } from "./vo/PetRebornVo";
import { Cache } from "../../cache/Cache";
import { GlobalStyle } from "../../../common/global/GlobalStyle";
import { HTMLUtil } from "../../../../com/gengine/utils/HTMLUtil";
import { TPetReincarnate } from "../../../../Message/Db/Tables/TPetReincarnate";
import { FilterConst } from "../../../component/gconst/FilterConst";
import { PetExperienceConfig } from "../../resource/PetExperienceConfig";
import { GlobalClass } from "../../../../com/mui/core/GlobalClass";
import { ImagesConst } from "../../resource/ImagesConst";
import { SMoney } from "../../../../Message/Game/SMoney";
import { ECategory } from "../../../../Message/Public/ECategory";
import { EProp } from "../../../../Message/Public/EProp";
import { SVIPInfo } from "../../../../Message/Game/SVIPInfo";
import { ObjCreate } from "../common/ObjCreate";
import { GTextFormat } from "../../../common/GTextFormat";
import { FontUtil } from "../../../common/font/FontUtil";
import { PetItem } from "./PetItem";
import { BgItem } from "../common/BgItem";
import { ItemData } from "../../resource/info/ItemData";
import { MountReinBuyPart } from "../mounts/mount/MountReinBuyPart";
import { WuXingPropertyDistribution } from "./WuXingPropertyDistribution";
import { PetProcessBar } from "./PetProcessBar";
import { PetRebornAttrPanel } from "./PetRebornAttrPanel";
import { GTextFiled } from "../../../../com/mui/controls/GTextFiled";
import { ScaleBitmap } from "../../../../com/mui/display/ScaleBitmap";
import { GButton } from "../../../../com/mui/controls/GButton";
import { GImageBitmap } from "../../../../com/mui/controls/GImageBitmap";
import { GCheckBox } from "../../../../com/mui/controls/GCheckBox";
type int = number;
//class PetRebornPanel
    
    export  class PetRebornPanel extends PetNewBaseView
    {
        constructor()
        {
            super();
            this._fightAttrLabelArray = Language.getString(54623).split(",");
            this._baseAttrLabelArray = Language.getString(54553).split(",");
            return;
        }

        public /* override */ updateByPetInfo(arg1: SPetInfo): void
        {
            if (this._index > 0) 
            {
                if (PetUtil.canReborn(arg1)) 
                {
                    if (this._mainItem.dragSource != arg1) 
                    {
                        this._mainItem.dragSource = arg1;
                        this._rebornItem.dragSource = arg1;
                        this._petReincarnate = PetReincarnateConfig.instance.getItemByTpye(arg1.reinLevel + 1);
                        if (this._petReincarnate) 
                        {
                            this.goodsItem = this._petReincarnate;
                            this.costTxt = this._petReincarnate.cost;
                            Dispatcher.dispatchEvent(new DataEvent(EventName.PetRebornShowReq, arg1.uid));
                        }
                    }
                }
                else 
                {
                    MsgManager.showRollTipsMsg(Language.getString(28020));
                    return;
                }
            }
            var loc1;
            var loc2=((loc1 = this)._index + 1);
            loc1._index = loc2;
            return;
        }

        /* internal  */onRebornHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            var e: Object /* flash.events.MouseEvent */;
            var onBtnClickHandler: Function;

            var loc1;
            onBtnClickHandler = null;
            e = arg1;
            onBtnClickHandler = (arg1: int): void
            {
                var loc1=null;
                if (arg1 == Alert.OK) 
                {
                    loc1 = new PetRebornVo();
                    loc1.petUid = _mainItem.petInfo.uid;
                    loc1.autoBuy = _autoBuyCB.selected;
                    loc1.useBind = _useBindCB.selected;
                    Dispatcher.dispatchEvent(new DataEvent(EventName.PetReborn, loc1));
                }
                return;
            }
            if (this._mainItem.petInfo && PetUtil.canReborn(this._mainItem.petInfo) && this._petReincarnate) 
            {
                if (this._autoBuyCB.selected == false && this._itemData.itemAmount < this._petReincarnate.amount) 
                {
                    MsgManager.showRollTipsMsg(Language.getString(28000));
                    return;
                }
                if (Cache.instance.role.money.coin + Cache.instance.role.money.coinBind < this._petReincarnate.cost) 
                {
                    MsgManager.showRollTipsMsg(Language.getString(28001));
                    return;
                }
                Alert.show(Language.getStringByParam(28026, this._rebornLevel), null, Alert.OK | Alert.CANCEL, null, onBtnClickHandler);
            }
            return;
        }

        /* internal  */set costTxt(arg1: int)
        {
            var loc1=Cache.instance.role.money.coin + Cache.instance.role.money.coinBind;
            var loc2=loc1 >= arg1 ? GlobalStyle.color2 : GlobalStyle.color7;
            this._costTxt.htmlText = arg1 <= 0 ? Language.getStringByParam(28010, "") : Language.getStringByParam(28010, HTMLUtil.addColor(arg1.toString(), loc2));
            return;
        }

        /* internal  */set goodsItem(arg1: TPetReincarnate)
        {
            if (this._mainItem && this._mainItem.dragSource && arg1) 
            {
                this._goodsItem.setItemCode(arg1.code, arg1.amount);
                this._goodsItem.baseItem.filters = this._toolNum < arg1.amount ? [FilterConst.colorFilter2] : [];
            }
            else 
            {
                this._goodsItem.setItemCode(0);
            }
            return;
        }

        /* internal  */set level(arg1: int)
        {
            if (arg1 < 0) 
            {
                this._levelTxt.text = Language.getStringByParam(28016, "");
                this._contrastLevelTxt.text = "";
            }
            else 
            {
                this._rebornLevel = arg1;
                this._levelTxt.text = Language.getStringByParam(28016, arg1);
                this._contrastLevelTxt.text = Language.getStringByParam(28025, arg1);
            }
            return;
        }

        /* internal  */set grow(arg1: int)
        {
            this._growTxt.htmlText = arg1 < 0 ? Language.getStringByParam(28018, "") : Language.getStringByParam(28018, HTMLUtil.addColor(arg1.toString(), "#F1FFB1"));
            return;
        }

        /* internal  */set intelligence(arg1: int)
        {
            this._intelligence.htmlText = arg1 < 0 ? Language.getStringByParam(28019, "") : Language.getStringByParam(28019, HTMLUtil.addColor(arg1.toString(), "#F1FFB1"));
            return;
        }

        public clear(arg1: Object /* flash.events.MouseEvent */=null): void
        {
            this._mainItem.dragSource = null;
            this._rebornItem.dragSource = null;
            this._goodsItem.itemData = null;
            this._arrow.bitmapData = null;
            this._levelChangeTxt.text = "";
            this.level = -1;
            this.grow = -1;
            this.intelligence = -1;
            this.costTxt = 0;
            this._petReincarnate = null;
            this.goodsItem = this._petReincarnate;
            this._WuXingProperty.clean();
            this._fightAttrPanel.clear();
            this._baseAttrPanel.clear();
            return;
        }

        public petRebornShowReqSuccess(arg1: SPetInfo, arg2: SPetInfo): void
        {
            var loc1=0;
            var loc5=null;
            var loc6=NaN;
            var loc2=[];
            var loc3=[];
            var loc4=[];
            if (arg1 && arg2) 
            {
                this._fightAttrPanel.resetPos();
                loc5 = arg2.fightAttribute;
                loc2.push(loc5.physicalAttack);
                loc2.push(loc5.magicAttack);
                if (loc5.physicalAttack > 0) 
                {
                    this._fightAttrPanel.hideAttr(1);
                }
                else 
                {
                    this._fightAttrPanel.hideAttr(0);
                }
                loc2.push(loc5.physicalDefense);
                loc2.push(loc5.magicDefense);
                loc2.push(loc5.hit);
                loc2.push(loc5.jouk);
                loc2.push(loc5.physicalCrit + loc5.magicCrit);
                loc2.push(loc5.pass);
                loc2.push(loc5.toughness);
                loc2.push(loc5.relief);
                loc3 = PetUtil.getSpiritAddValueArray(arg2);
                loc2.push(loc5.power);
                loc2.push(loc5.agile);
                loc2.push(loc5.habitus);
                loc2.push(loc5.brains);
                loc2.push(loc5.spiritual);
                loc3 = loc3.concat(PetUtil.getGrowthAddValueArray(arg2));
                loc4 = PetUtil.getRebornAddValueArray(arg1.fightAttribute, arg2.fightAttribute);
                this._fightAttrPanel.updateValue(loc2.slice(0, 10));
                this._fightAttrPanel.updateAddValue(loc3.slice(0, 10));
                this._fightAttrPanel.updateRebornAddValue(loc4.slice(0, 10));
                this._baseAttrPanel.updateValue(loc2.slice(10, 15));
                this._baseAttrPanel.updateAddValue(loc3.slice(10, 15));
                this._baseAttrPanel.updateRebornAddValue(loc4.slice(10, 15));
                this.level = arg2.level;
                this.grow = arg2.growth;
                this.intelligence = arg2.spirit;
                loc6 = PetExperienceConfig.instance.getValueByLevel(PetExperienceConfig.getLevel(arg2));
                this._expBar.setValue(arg2.experience, loc6);
                this._WuXingProperty.data = [loc5.goldRelief, loc5.woodRelief, loc5.waterRelief, loc5.fireRelief, loc5.earthRelief];
                loc1 = arg2.level - this._mainItem.petInfo.level;
                if (loc1 < 0) 
                {
                    this._arrow.bitmapData = GlobalClass.getBitmapData(ImagesConst.RangeDecline);
                    this._levelChangeTxt.text = Math.abs(loc1).toString();
                    this._levelChangeTxt.textColor = GlobalStyle.color7Uint;
                }
                else if (loc1 > 0) 
                {
                    this._arrow.bitmapData = GlobalClass.getBitmapData(ImagesConst.RangeRaise);
                    this._levelChangeTxt.text = Math.abs(loc1).toString();
                    this._levelChangeTxt.textColor = GlobalStyle.color5Uint;
                }
                else 
                {
                    this._arrow.bitmapData = null;
                    this._levelChangeTxt.text = "";
                }
            }
            return;
        }

        protected /* override */ onMoneyUpdateHandler(arg1: SMoney=null): void
        {
            return;
        }

        public /* override */ update(arg1: Object, ... rest): void
        {
            super.update(arg1, rest);
            this._index = 0;
            this.clear();
            return;
        }

        protected /* override */ onPackChangeHandler(arg1: Object=null): void
        {
            if (this._buyItem) 
            {
                this._toolNum = Cache.instance.pack.backPackCache.getItemCountByCategoryAndType(ECategory._ECategoryProp, EProp._EPropPetReincarnate);
                if (this._toolNum > 0) 
                {
                    this._buyItem.baseItem.filters = null;
                }
                else 
                {
                    this._buyItem.baseItem.filters = [FilterConst.colorFilter2];
                }
                this._buyItem.itemData.itemAmount = this._toolNum;
                this.goodsItem = this._petReincarnate;
            }
            return;
        }

        protected /* override */ onVIPInfoUpdateCommandHandler(arg1: SVIPInfo): void
        {
            return;
        }

        protected /* override */ createDisposedChildrenImpl(): void
        {
            super.createDisposedChildrenImpl();
            ObjCreate.createFlowerBg(0, 0, 388, 303, this);
            ObjCreate.createBg(0, 305, 388, 95, this);
            ObjCreate.createBg(390, 0, 193, 400, this);
            ObjCreate.createBg(10, 235, 368, 60, this);
            ObjCreate.createBg(390, 0, 160, 25, this, ImagesConst.TileBg);
            ObjCreate.createGImageBitmap(ImagesConst.PetRebornBg, 1, 1, this);
            ObjCreate.createGImageBitmap("PetRebornPropertyTitle.png", 395, 3, this);
            ObjCreate.createBg(16, 28, 38, 38, this, ImagesConst.PackItemBg);
            ObjCreate.createBg(107, 112, 38, 38, this, ImagesConst.PackItemBg);
            ObjCreate.createTextField(Language.getString(28007), 7, 5, 70, 20, this, new GTextFormat(FontUtil.songtiName, 12, 15788607, true));
            ObjCreate.createTextField(Language.getString(28008), 195, 5, 70, 20, this, new GTextFormat(FontUtil.songtiName, 12, 15788607, true));
            this._mainItem = new PetItem();
            this._mainItem.addEventListener(flash.events.MouseEvent.CLICK, this.clear);
            ObjCreate.setObjAttri(this._mainItem, 18, 30, 34, 34, this);
            this._goodsItem = new BgItem();
            this._goodsItem.isDragAble = false;
            this._goodsItem.baseItem.isShowLock = false;
            ObjCreate.setObjAttri(this._goodsItem, 198, 28, -1, -1, this);
            this._rebornItem = new PetItem();
            ObjCreate.setObjAttri(this._rebornItem, 108, 113, 36, 36, this);
            this._rebornBtn = ObjCreate.createGButton(Language.getString(28011), 90, 203, 70, 26, this, "ButtonSpecial");
            this._rebornBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onRebornHandler);
            this._costTxt = ObjCreate.createGTextField(Language.getStringByParam(28010, ""), 80, 180, 90, 20, this, GlobalStyle.textFormat2);
            ObjCreate.createBitmap(ImagesConst.Tongqian, 160, 179, this);
            this._rebornTxt = ObjCreate.createGTextField("", 265, 58, 150, 40, this, GlobalStyle.setTextFormatLeading(GlobalStyle.textFormat6, 5));
            this._rebornTxt.multiline = true;
            this._rebornTxt.wordWrap = true;
            this._rebornTxt.htmlText = Language.getString(28009);
            this._itemData = new ItemData(14156000);
            this._buyItem = new MountReinBuyPart(ECategory._ECategoryProp, EProp._EPropPetReincarnate);
            this._buyItem.itemData = this._itemData;
            ObjCreate.setObjAttri(this._buyItem, 15, 228, -1, -1, this);
            this._WuXingProperty = new WuXingPropertyDistribution();
            this._WuXingProperty.data = [100, 90, 90, 90, 90];
            ObjCreate.setObjAttri(this._WuXingProperty, 235, 88, -1, -1, this);
            this._useBindCB = ObjCreate.createCheckBox(Language.getString(70186), 240, 241, 121, 20, this);
            this._autoBuyCB = ObjCreate.createCheckBox(Language.getString(70187), 240, 265, 121, 20, this);
            this._useBindCB.selected = true;
            this._expainTxt = ObjCreate.createGTextField("", 1, 310, 388, 90, this, GlobalStyle.setTextFormatLeading(GlobalStyle.textFormat1, 5));
            this._expainTxt.multiline = true;
            this._expainTxt.wordWrap = true;
            this._expainTxt.htmlText = Language.getString(28003);
            this._lineOne = ObjCreate.createBg(396, 96, 175, 2, this, ImagesConst.SplitLine);
            this._lineTwo = ObjCreate.createBg(396, 293, 175, 2, this, ImagesConst.SplitLine);
            this._contrastLevelTxt = ObjCreate.createGTextField("", 412, 99, 160, 20, this, GlobalStyle.textFormat6);
            this._levelTxt = ObjCreate.createGTextField(Language.getStringByParam(28016, 50), 398, 30, 80, 20, this, GlobalStyle.textFormat8);
            this._expTxt = ObjCreate.createGTextField(Language.getString(28017), 398, 50, 40, 20, this);
            this._growTxt = ObjCreate.createGTextField(Language.getStringByParam(28018, ""), 398, 72, 80, 20, this, GlobalStyle.textFormat5);
            this._intelligence = ObjCreate.createGTextField(Language.getStringByParam(28019, ""), 520, 72, 80, 20, this, GlobalStyle.textFormat4);
            this._arrow = ObjCreate.createBitmap("", 470, 31, this);
            this._levelChangeTxt = ObjCreate.createGTextField("", 485, 30, 80, 20, this);
            this._expBar = new PetProcessBar(ImagesConst.GreenBar10, 140);
            this._expBar.move(436, 53);
            this._expBar.setValue(0, 0);
            this.addChild(this._expBar);
            this._fightAttrPanel = new PetRebornAttrPanel(this._fightAttrLabelArray, GlobalStyle.textFormat4, null, null, 18);
            ObjCreate.setObjAttri(this._fightAttrPanel, 394, 115, -1, -1, this);
            this._baseAttrPanel = new PetRebornAttrPanel(this._baseAttrLabelArray, GlobalStyle.textFormat5);
            ObjCreate.setObjAttri(this._baseAttrPanel, 394, 300, -1, -1, this);
            this.onPackChangeHandler();
            return;
        }

        protected /* override */ disposeImpl(arg1: Boolean=true): void
        {
            super.disposeImpl(arg1);
            return;
        }

        /* internal */ /* var */_WuXingProperty: WuXingPropertyDistribution;

        /* internal */ /* var */_expainTxt: GTextFiled;

        /* internal */ /* var */_lineOne: ScaleBitmap;

        /* internal */ /* var */_lineTwo: ScaleBitmap;

        /* internal */ /* var */_arrow: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_levelChangeTxt: GTextFiled;

        /* internal */ /* var */_expBar: PetProcessBar;

        /* internal */ /* var */_levelTxt: GTextFiled;

        /* internal */ /* var */_costTxt: GTextFiled;

        /* internal */ /* var */_growTxt: GTextFiled;

        /* internal */ /* var */_intelligence: GTextFiled;

        /* internal */ /* var */_fightAttrLabelArray: Array<any>;

        /* internal */ /* var */_baseAttrLabelArray: Array<any>;

        /* internal */ /* var */_petReincarnate: TPetReincarnate;

        /* internal */ /* var */_toolNum: int;

        /* internal */ /* var */_rebornLevel: int;

        /* internal */ /* var */_index: int;

        /* internal */ /* var */_mainItem: PetItem;

        /* internal */ /* var */_mainItemBg: ScaleBitmap;

        /* internal */ /* var */_goodsItem: BgItem;

        /* internal */ /* var */_rebornItem: PetItem;

        /* internal */ /* var */_rebornBtn: GButton;

        /* internal */ /* var */_rebornTxt: GTextFiled;

        /* internal */ /* var */_title: GImageBitmap;

        /* internal */ /* var */_fightAttrPanel: PetRebornAttrPanel;

        /* internal */ /* var */_expTxt: GTextFiled;

        /* internal */ /* var */_baseAttrPanel: PetRebornAttrPanel;

        /* internal */ /* var */_contrastLevelTxt: GTextFiled;

        /* internal */ /* var */_useBindCB: GCheckBox;

        /* internal */ /* var */_autoBuyCB: GCheckBox;

        /* internal */ /* var */_buyItem: MountReinBuyPart;

        /* internal */ /* var */_itemData: ItemData;
    }
